<template>
	<view class="search">
		<up-search placeholder="请输入搜索内容" v-model="keyword" @search="getList(true)" @custom="getList(true)"></up-search>
	</view>
	<scroll-view @scrolltolower="handleIsBotton" refresherpulling="handleIsRefresh" style="height: 1150px"
		scroll-y="true" class="scroll-Y">

		<view class="wrap">
			<view class="item" v-for="(item, index) in activityList" :key="index">
				<uni-card @click="details(item.id)">
					<u-row>
						<u-col :span="item.img?8:12">
							<view>
								<view class="item-title">{{ item.title }}</view>
								<view class="message">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.outline }}</view>
								
								<!-- 时间戳 -->
								<!-- <view class="time">发布于：{{ item.releaseTime }}</view> -->
							</view>
						</u-col>
						<u-col :span="4" style="height: 160rpx;">
							<image v-if="item.img" :src="config.baseUrl+item.img"></image>

						</u-col>
					</u-row>
					<u-row>
						<u-col :span="4">
							<view>
								<uni-tag :text="item.responsiblePerson" plain size="mini" type="warning">
								</uni-tag>
							</view>
						</u-col>
						<u-col :span="8" style="text-align: right;">
							{{item.releaseTime}}
						</u-col>
					</u-row>
					<!-- 用户信息 -->

					<!-- 图片容器 -->

					<!--活动简介 -->

					<!-- 点赞、浏览量、收藏 -->
					<view class="action-buttons">
						<view @click.stop="handUp(item.id,index)">
							<uni-icons v-if="!item.isHandUp" type="hand-up" size="26"></uni-icons>
							<uni-icons v-if="item.isHandUp" type="hand-up-filled" color="#FF8C00" size="26"></uni-icons>
							<view>{{item.handUpCount}}</view>
						</view>
						<view>
							<uni-icons type="eye" size="26"></uni-icons>
							<view>{{item.viewCount}}</view>
						</view>
						<view @click.stop="star(item.id,index)">
							<uni-icons v-if="!item.isCollect" type="star" size="26"></uni-icons>
							<uni-icons v-if="item.isCollect" type="star-filled" color="#FF8C00" size="26"></uni-icons>
							<view>{{item.collectCount}}</view>
						</view>
					</view>
				</uni-card>
			</view>
		</view>
	</scroll-view>
</template>

<script setup>
	import {
		releaseList
	} from "@/api/system/activity";
	import {
		signUp,
		signIn,
		signInInfo,
		signUpInfo
	} from "@/api/system/record"
	import {
		onMounted,
		ref
	} from 'vue';
	import config from "@/config";

	const keyword = ref('');
	const activityList = ref([]);
	const loading = ref(true);
	const total = ref(0);

	//分页信息
	const pageInfo = ref({
		pageNum: 1,
		pageSize: 10
	})
	//获取数据
	function getList(search) {
		loading.value = true;
		releaseList({
			"keyword": keyword.value
		}).then(response => {
			total.value = response.total;
			if (search) {
				activityList.value = response.rows
			} else if (activityList.value.length < total.value) {
				activityList.value.push(...response.rows);
			}
			loading.value = false;
		});
	}
	onMounted(() => {
		getList()
	})


	// const status = ref('loadmore');

	// function onReachBottom() {
	// 	if (page.value >= 3) return;
	// 	status.value = 'loading';
	// 	page.value++;
	// 	setTimeout(() => {
	// 		list.value += 10;
	// 		if (page.value >= 3) status.value = 'nomore';
	// 		else status.value = 'loading';
	// 	}, 2000);
	// }

	function details(id) {
		console.log(id);
		uni.navigateTo({
			url: '/pages/activity/details?id=' + id
		});
	}
	const handUp = (id, index) => {
		signUp(id).then(res => {

			activityList.value[index].isHandUp = res.data
			res.data ? activityList.value[index].handUpCount++ : activityList.value[index].handUpCount--

		})
	}
	const star = (id, index) => {
		signIn(id).then(res => {
			activityList.value[index].isCollect = res.data
			res.data ? activityList.value[index].collectCount++ : activityList.value[index].collectCount--
		})
	}

	//到达底部
	const handleIsBotton = () => {
		pageInfo.value.pageNum++;
		getList();
	}

	//到达底部
	const handleIsRefresh = () => {
		pageInfo.value.pageNum = 1;
		getList();
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */
	.item-title {
		font-size: 16px;
		font-weight: bold;
		
		overflow: hidden;
		/* 隐藏溢出的内容 */
		text-overflow: ellipsis;
		/* 显示省略号 */
		-webkit-line-clamp: 3;
		/* 限制在2行内 */
		line-clamp: 1;
		/* 非webkit浏览器可能也支持 */
		display: -webkit-box;
		/* 启用对-webkit-line-clamp的支持 */
		-webkit-box-orient: vertical;

	}

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		// align-items: center;
		// justify-content: center;
		padding: 15px 0;
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		// justify-content: center;
		// align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
			height: 100%;
		}
	}

	.search {
		margin: 10px;
	}

	.swiper image {
		width: 100%;
		height: 100%;
		border-radius: 10px;
	}


	.user-actions {
		// display: flex;
		// align-items: center;
	}

	.avatar {
		width: 30px;
		height: 30px;
		border-radius: 50%;
	}

	.nickname {
		margin-right: auto;
		font-size: 20px;
	}

	.message {
		overflow: hidden;
		/* 隐藏溢出的内容 */
		text-overflow: ellipsis;
		/* 显示省略号 */
		-webkit-line-clamp: 3;
		/* 限制在2行内 */
		line-clamp: 3;
		/* 非webkit浏览器可能也支持 */
		display: -webkit-box;
		/* 启用对-webkit-line-clamp的支持 */
		-webkit-box-orient: vertical;
		/* 设置为垂直盒子 */

	}

	// .images-wrap {
	// 	display: flex;
	// 	flex-wrap: wrap;
	// }

	// .image-item {
	// 	width: calc(33.333% - 5px);
	// 	/* 假设每行三张图片，减去间距 */
	// 	margin-right: 5px;
	// 	height: 100px;
	// 	/* 图片高度，根据需要调整 */
	// 	margin-bottom: 5px;
	// 	border-radius: 5px;
	// }

	.time {
		font-size: 12px;
		// color: #999;
	}

	.action-buttons {
		text-align: center;
		display: flex;
		justify-content: space-around;
		margin-top: 5px;
	}

	.big-image-modal {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.8);
		display: flex;
		// justify-content: center;
		// align-items: center;
		z-index: 10;
	}
</style>